package com.shaoshaohuo.app.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.Browser;
import com.shaoshaohuo.app.utils.ImageLoadUtil;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class BrowserRecordAdapter extends MyBaseAdapter<Browser> {
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	private  Context activity;

	public BrowserRecordAdapter(Context ctx, List<Browser> list, boolean flag) {
		super(ctx, list, flag);
	}

	@Override
	public View getView(int pos, View view, ViewGroup group) {
		if(view==null){
			view = View.inflate(context, R.layout.item_browser_recoder, null);
		}
		ViewHolder holder = ViewHolder.getHolder(view);
		Browser browser = list.get(pos);
		
		if(browser.getSmall_images()!=null&&browser.getSmall_images().size()>0){
			ImageLoader.getInstance().displayImage(browser.getSmall_images().get(0), holder.image,
				ImageLoadUtil.getDisplayImageOptions(R.drawable.pic_empty_list_ad));
		}else{
			holder.image.setImageResource(R.drawable.pic_empty_list_ad);
		}
		holder.name.setText(browser.getCatname());
		holder.product.setText(browser.getVarieties());
		holder.price.setText(browser.getMoney() != null ? browser.getMoney() : "");
//		Log.e("tag", browser.getTime());
		long timeMillis = Long.parseLong(browser.getTime());
//		Log.e("tag", ""+timeMillis+"++++++++++++++++++"+dateFormat.format(new Date(timeMillis)));
		String timeText = dateFormat.format(new Date(timeMillis*1000));//PHP坑死人啊  
		holder.time.setText(timeText);
//		holder.time.setText(dateFormat.format(new Date(timeMillis)));
		return view;
	}

	static class ViewHolder {
		public ImageView image;
		public TextView name;
		public TextView time;
		public TextView price;
		public TextView product;

		private ViewHolder(View view) {
			image = (ImageView) view.findViewById(R.id.iv_picture);
			name = (TextView) view.findViewById(R.id.tv_name);
			product = (TextView) view.findViewById(R.id.tv_product);
			price = (TextView) view.findViewById(R.id.tv_price);
			time = (TextView) view.findViewById(R.id.tv_time);
		}

		public static ViewHolder getHolder(View view) {
			return (ViewHolder) (view.getTag() != null ? view.getTag() : new ViewHolder(view));
		}
	}
}
